﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using VacationDaysCommons;
using VacationDaysDatabase;

namespace VacationDaysClient.CustomControls
{
    /// <summary>
    /// Interaction logic for UserInboxControl.xaml
    /// </summary>
    public partial class UserInboxControl : UserControl
    {
        private ObservableCollection<VDMessageItem> _userMessagesCollection = new ObservableCollection<VDMessageItem>();
        public ObservableCollection<VDMessageItem> UserMessagesCollection { get { return _userMessagesCollection; } }


        private Guid userId;

        public UserInboxControl(Guid UserId)
        {
            userId = UserId;
            InitializeComponent();
            RefreshMessages();
        }
        public UserInboxControl()
        {
            InitializeComponent();
        }

        private void RefreshMessages()
        {
            using (VDMessengerServiceClient vm = new VDMessengerServiceClient())
            {
                var userMessages = vm.GetUserMessages(userId);
                _userMessagesCollection.Clear();
                foreach (var userMessage in userMessages)
                {
                    _userMessagesCollection.Add(userMessage);
                }
            }
        }

        private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            VDMessageItem userMessage = listView1.SelectedItem as VDMessageItem;

            if (userMessage != null)
            {
                textBox1.Text = userMessage.MessageText;
            }
        }

    }
}
